﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using StillVoiceCommon;

namespace TeamTime
{
    public partial class CompanyRegNumControl : System.Web.UI.UserControl
    {
        public event System.EventHandler CompanyTypeChanged;
        private void CompanyFormControl_CompanyTypeChanged(object sender, EventArgs e) { }
        public delegate void CompanyTypeChangeEventHandler(object sender, EventArgs e);

        public string CompanyRegNum
        {
            get
            {
                return this.txtCompanyRegistrationNum1.Text + txtCompanyRegistrationNum2.Text + txtCompanyRegistrationNum3.Text;
            }
            set
            {
                value = (value + "000000000000").Substring(0, 12); //Pad it first
                this.txtCompanyRegistrationNum1.Text = value.Substring(0, 4);
                this.txtCompanyRegistrationNum2.Text = value.Substring(4, 6);
                this.txtCompanyRegistrationNum3.Text = value.Substring(10, 2);
            }
        }
        public int CompanyTypeID
        {
            get
            {
                return Convert.ToInt32(this.ddlCompanyTypeID.SelectedValue);
            }
            set
            {
                this.ddlCompanyTypeID.SelectedValue = value.ToString();
                ddlCompanyTypeID_SelectedIndexChanged(null, null);
            }
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Functions.dropDownListPopulate(this.ddlCompanyTypeID, "select ID, Description from CompanyType order by Description ", "ID", "Description");
                HideShowRegNum();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                //Functions.dropDownListPopulate(this.ddlCompanyTypeID, "select ID, Description from CompanyType order by Description ", "ID", "Description");
                //ddlCompanyTypeID_SelectedIndexChanged( sender,e);
            }
        }

        protected void ddlCompanyTypeID_SelectedIndexChanged(object sender, EventArgs e)
        {

            HideShowRegNum();
            if (this.CompanyTypeChanged != null)
                this.CompanyTypeChanged(sender, e);

            

        }
        private void HideShowRegNum()
        {
            Int16 i = Convert.ToInt16(this.ddlCompanyTypeID.SelectedValue);
            if (i == 1 || i == 2 || i == 5)
                this.spRegNum.Visible = true;
            else
            {
                this.spRegNum.Visible = false;
                //this.re.Text
            }
            //1	PTY Ltd
            //2	Closed Corporation
            //3	Partnership/Sole Prop
            //4	Trust
            //5	Non-profit organisation
            //6	Other
        }
    }
}